﻿using System;
namespace Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paring4_vastus", Namespace="http://producers.taitis.xtee.riik.ee/producer/taitis", Target=typeof(Paring4Vastus))]
    public class Paring4VastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParing4Vastus clazz;
        
        public Paring4VastusSerializer(IParing4Vastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("teade");
            if (clazz.Teade!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Teade))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Teade");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("volgnik_jada");
            if (clazz.VolgnikJada!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("volgnik_jada_item", "http://producers.taitis.xtee.riik.ee/producer/taitis", clazz.VolgnikJada.Count);
                for (int x = 0; ((clazz.VolgnikJada != null) 
                            && (x < clazz.VolgnikJada.Count)); x = (x + 1)) {
                    if (clazz.VolgnikJada[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaVolgnikJada = this.GetMetaData(clazz.VolgnikJada[x]);
                        Writer.WriteTypeAttribute(metaVolgnikJada.TypeQualifiedName.Namespace, metaVolgnikJada.TypeQualifiedName.Name);
                        metaVolgnikJada.NewSerializer(clazz.VolgnikJada[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : VolgnikJada");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "teade")) {
                goto teade;
            }
            else {
                if ((Reader.LocalName == "volgnik_jada")) {
                    goto volgnik_jada;
                }
                else {
                    return;
                }
            }
        teade:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paring4_vastus>teade");
            }
            clazz.Teade = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("teade")).Value;
            goto START;
        volgnik_jada:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paring4_vastus>volgnik_jada");
            }
            clazz.VolgnikJada = new System.Collections.Generic.List<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IVolgnikJadaItem>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("volgnik_jada");
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "item")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>paring4_vastus>volgnik_jada>item");
                    }
                    global::Xtee.Core.SerializationMetadata metaVolgnikJada = this.GetMetaData<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IVolgnikJadaItem>(Reader, "volgnik_jada_item", "http://producers.taitis.xtee.riik.ee/producer/taitis");
                    global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IVolgnikJadaItem item = metaVolgnikJada.NewEntity<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IVolgnikJadaItem>();
                    clazz.VolgnikJada.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("item");
                        metaVolgnikJada.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
    }
}
